home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_543 / mousexy / mouse-xy.asm < prev    next >
Assembly Source File  |  1992-05-06  |  19KB  |  728 lines

  1. *    Mouse-xy
  2. *    By Preben Nielsen
  3. *
  4. *      This utility opens a little window in which it shows
  5. *    the mouse coordinates and the color at that position
  6. *      If the left mousebutton is being held down, the coordinates
  7. *    is relative to the spot where the mouse was when button got
  8. *    pressed.
  9. *
  10. *      Double-clicking the right mousebutton while the window is
  11. *    active will make it try to jump to another screen (if any).
  12. *
  13. *      The size of the window and the use of colors in it depends on
  14. *    the version of the Kickstart/Workbench (1.2/1.3 vs. 2.?) and
  15. *    the screen mode (LORES vs. HIRES)
  16. *
  17. *    NOTE:    There's no need to 'RUN' or 'RUNBACK' this program from the
  18. *        CLI. It is auto-detaching.
  19. *
  20. *HISTORY
  21. *          Made with Hisoft V2.12
  22. *
  23. *  V1.0   17-Mar-91: First attempt
  24. *         19-Mar-91: Added color monitoring
  25. *         21-Mar-91: Even Works while intuition locks all layers because
  26. *                    I now patch 'LockLayerRom' and 'UnLockLayerRom'.
  27. *                    You can now monitor the coordinates even while you
  28. *                    are sizing  window, dragging window/icons and even
  29. *                    when you select menus
  30. *         07-Apr-91: I Now patch 'CloseScreen' so that the window
  31. *                    automatically evacuates any closing screen.
  32. *         19-Apr-91: Made some modifications to make it look better
  33. *                    under WB2.0 (haven't actually tried it yet).
  34. *  V1.1   02-Aug-91: Damned - why didn't anyone tell me that Mouse-xy
  35. *                    looked awful (strange) under kickstart 1.3. It
  36. *                    shouldn't change its appearance like that except
  37. *                    under kickstart 2.x ! Well, it has been fixed now.
  38. *         15-Aug-91: Rewrote code to make it more safe to jump from
  39. *                    screen to screen.
  40. *         22-Aug-91: Now Mouse-xy can perfecty emulate the 2.x way of
  41. *                    using colors in windows.
  42.  
  43.     OPT O+
  44.     OPT O1+            ; Tells when a branch could be optimised to short
  45. ;    OPT i+            ; Tells when '#' is probably missing
  46.  
  47. LMBBUT        =$BFE001    ; Bit 6
  48.  
  49.         incdir        "AsmInc:"
  50.         include        "P.i"
  51.         include        "Intui.i"
  52.         include        "Detach.i"
  53.         include        "relMacros.i"
  54.         include        "exec/exec_lib.i"
  55.         include        "exec/memory.i"
  56.         include        "exec/interrupts.i"
  57.         include        "intuition/intuition.i"
  58.         include        "intuition/intuition_lib.i"
  59.         include        "graphics/graphics_lib.i"
  60.         include        "libraries/dos_lib.i"
  61.         include        "libraries/dosextens.i"
  62.         include        "hardware/intbits.i"
  63.  
  64. xy_Change_B    =SIGBREAKB_CTRL_D
  65. xy_Change_F    =1<<xy_Change_B
  66. LMB_Change_B    =SIGBREAKB_CTRL_E
  67. LMB_Change_F    =1<<LMB_Change_B
  68. Remove_Screen_B    =SIGBREAKB_CTRL_F
  69. Remove_Screen_F =1<<Remove_Screen_B
  70. WaitMask    =xy_Change_F|LMB_Change_F|Remove_Screen_F
  71.  
  72. DB        EQUR        A4
  73.  
  74.  dcDeclare    A4
  75.  dcWord        Relative        ; 0 means absolute coordinates
  76.  dcAPtr        xyProcess
  77.  dcAPtr        GraphBase
  78.  dcAPtr        IntuiBase
  79.  dcAPtr        WBenchMsg        ; Message from Workbench
  80.  dcAPtr        ThisWindow        ; APtr to Window
  81.  dcAPtr        ThisScreen        ; APtr to Screen
  82.  dcAPtr        DeadScreen        ; Screen to be closed
  83.  dcAPtr        Rp            ; APtr to RastPort
  84.  dcAPtr        Up            ; APtr to UserPort
  85.  dcAPtr        Font            ; Window-font
  86.  dcWord        yPos            ; y-position of text in window
  87.  dcWord        xPos            ; x-position of text in window
  88.  dcWord        Height            ; Height of window
  89.  dcWord        Width            ; Width of window
  90.  dcWord        Version            ; Kickstart version ID
  91.  dcWord        mx            ; \The order is important
  92.  dcWord        my            ; /
  93.  dcWord        ox            ; \The order is important
  94.  dcWord        oy            ; /
  95.  dcWord        rx            ; \The order is important
  96.  dcWord        ry            ; /
  97.  dcWord        OldColor        ; Old color
  98.  dcLong        Class            ; im_Class
  99.  dcWord        Code            ; im_Code
  100.  dcLong        Micros            ; \The order is important
  101.  dcLong        Seconds            ; /
  102.  dcLong        OldMicros        ; \The order is important
  103.  dcLong        OldSeconds        ; /
  104.  dcArea        xyInterrupt,IS_SIZE    ; Interrupt structure
  105.  dcEnd
  106.  
  107. Start        DetachSingle    <'Mouse-xy'>,4000,0
  108.         dcAlloc                    ; Allocate memory for variables
  109.         dcReset                    ; Clear the memory
  110.         Prepare        Exec_Call
  111.         suba.l        A1,A1
  112.         CallLib        FindTask        ; Find us
  113.         move.l        D0,xyProcess(DB)
  114.         lea        WProcess(PC),A1
  115.         move.l        D0,(A1)
  116.         move.l        D0,A2
  117.         tst.l        pr_CLI(A2)
  118.         bne.S        GetLibs
  119.         lea        pr_MsgPort(A2),A0
  120.         CallLib        WaitPort        ; Wait for a message
  121.         lea        pr_MsgPort(A2),A0
  122.         CallLib        GetMsg                        then get it
  123.         move.l        D0,WBenchMsg(DB)    ; Save it for later reply
  124. GetLibs        lea        GfxName(PC),A1
  125.         CallLib        OldOpenLibrary
  126.         move.l        D0,GraphBase(DB)
  127.         beq.S        Error
  128.         lea        IntuiName(PC),A1
  129.         CallLib        OldOpenLibrary
  130.         move.l        D0,IntuiBase(DB)
  131.         beq.S        Error
  132.  
  133. SetInterrupt    Prepare        Exec_Call
  134.         lea        xyInterrupt(DB),A1    ; Start vertical-blanking interrupt-Server
  135.         move.b        #NT_INTERRUPT,LN_TYPE(A1); xyInterrupt->is_Node.ln_Type=NT_INTERRUPT
  136.         lea        xyIntName(PC),A0
  137.         move.l        A0,LN_NAME(A1)        ; xyInterrupt->is_Node.ln_Name=xyIntName
  138.         lea        xyIntServer(PC),A0
  139.         move.l        A0,IS_CODE(A1)        ; xyInterrupt->is_Code          =xyIntServer
  140.         move.l        DB,IS_DATA(A1)        ; xyInterrupt->is_Data          =DB
  141.         moveq        #INTB_VERTB,D0
  142.         CallLib        AddIntServer
  143.  
  144. GetFont        Prepare        Gfx_Call
  145.         lea        TxtAttr(PC),A0
  146.         CallLib        OpenFont
  147.         move.l        D0,Font(DB)
  148.         beq.S        Error
  149.  
  150. GetWindow    suba.l        A0,A0            ; Find any suitable screen
  151.         Call        FindOtherScreen
  152.         beq.S        Error
  153.         move.l        D0,A1
  154.         Call        OpenNewWindow
  155.         beq.S        Exit
  156.         move.l        D0,A0
  157.         Call        UseNewWindow
  158.  
  159. SetPatches    Call        AddPatches
  160.         bra.S        Main
  161.  
  162. Error
  163. Exit        Prepare        Exec_Call
  164. FreeInterrupt    lea        xyInterrupt(DB),A1
  165.         tst.l        IS_CODE(A1)        ; If this is set then server has been added
  166.         beq.S        FreeFont
  167.         moveq        #INTB_VERTB,D0
  168.         CallLib        RemIntServer
  169. FreeFont    Prepare        Gfx_Call
  170.         move.l        Font(DB),D0
  171.         beq.S        FreeIntui
  172.         move.l        D0,A1
  173.         CallLib        CloseFont
  174. FreeIntui    Prepare        Exec_Call
  175.         move.l        IntuiBase(DB),D0
  176.         beq.S        FreeGfx
  177.         move.l        D0,A1
  178.         CallLib        CloseLibrary
  179. FreeGfx        move.l        GraphBase(DB),D0
  180.         beq.S        ReplyWB
  181.         move.l        D0,A1
  182.         CallLib        CloseLibrary
  183. ReplyWB        move.l        WBenchMsg(DB),D2
  184.         beq.S        AllDone
  185.         CallLib        Forbid
  186.         move.l        D2,A1
  187.         CallLib        ReplyMsg        ; Reply WBenchMessage if we are started from WB
  188. AllDone        dcFree
  189.         moveq        #0,D0
  190.         rts
  191.  
  192. Main
  193. Change        Call        UpdateDisplay
  194. EventLoop    move.l        Up(DB),A0
  195.         moveq        #0,D0
  196.         moveq        #0,D1
  197.         move.b        MP_SIGBIT(A0),D1
  198.         bset        D1,D0
  199.         ori.l        #WaitMask,D0
  200.         Prepare        Exec_Call
  201.         CallLib        Wait
  202.         move.l        D0,D5
  203.         move.b        Relative(DB),D7
  204.         move.l        Up(DB),A0
  205.         moveq        #0,D0
  206.         move.b        MP_SIGBIT(A0),D0
  207.         btst        D0,D5
  208.         beq        CheckMouse
  209.  
  210. GetNextMsg    move.l        Up(DB),A0        ; Recieved a signal from intuition
  211.         Prepare        Exec_Call
  212.         CallLib        GetMsg
  213.         tst.l        D0
  214.         beq        CheckMouse
  215.         move.l        D0,A1
  216.         move.l        im_Class(A1),Class(DB)
  217.         move.w        im_Code(A1),Code(DB)
  218.         move.l        im_Seconds(A1),Seconds(DB)
  219.         move.l        im_Micros(A1),Micros(DB)
  220.         CallLib        ReplyMsg
  221.         move.l        Class(DB),D1
  222.         cmp.l        #CLOSEWINDOW,D1
  223.         beq.S        DoExit
  224.         cmp.l        #MOUSEBUTTONS,D1
  225.         beq.S        DoButtons
  226.  
  227.         tst.w        Version(DB)        ; No need to change color
  228.         beq.S        3$            ; under 1.2/1.3
  229.         cmp.l        #ACTIVEWINDOW,D1
  230.         bne.S        1$
  231.         Call        GetBackColor
  232.         move.w        D0,D2
  233.         Call        GetFrontColor
  234.         bra.S        2$
  235. 1$        cmp.l        #INACTIVEWINDOW,D1
  236.         bne.S        3$
  237.         moveq        #0,D2
  238.         moveq        #1,D0
  239. 2$        Prepare        Gfx_Call
  240.         move.l        Rp(DB),A1
  241.         CallLib        SetAPen
  242.         move.w        D2,D0
  243.         move.l        Rp(DB),A1
  244.         CallLib        SetBPen
  245. 3$        Call        UpdateDisplay        ; Do some refreshing
  246.         bra        GetNextMsg
  247.  
  248. DoExit        Call        RemPatches
  249.         bne.S        1$
  250.         Call        CloseOldWindow
  251.         bra        Exit
  252. 1$        Call        TellUser
  253.         bra        GetNextMsg
  254.  
  255. DoButtons    cmp.w        #MENUDOWN,Code(DB)
  256.         bne        GetNextMsg
  257.         Prepare        Intuition_Call        ; Check for double-click
  258.         movem.l        Seconds(DB),D2-D3
  259.         movem.l        OldSeconds(DB),D0-D1
  260.         movem.l        D2-D3,OldSeconds(DB)
  261.         CallLib        DoubleClick
  262.         tst.l        D0
  263.         beq        GetNextMsg
  264.         move.l        ThisScreen(DB),A0    ; Yes, a double-click
  265.         Call        FindOtherScreen        ; Find new suitable screen
  266.         beq.S        1$
  267.         move.l        D0,A1
  268.         Call        OpenNewWindow
  269.         beq.S        1$
  270.         Call        CloseOldWindow        ; We got a new window
  271.         move.l        D0,A0            ; Close the old window
  272.         Call        UseNewWindow        ; Start using the new window
  273. 1$        bra        GetNextMsg
  274.  
  275. CheckMouse    btst        #LMB_Change_B,D5
  276.         beq.S        1$
  277.         move.l        my(DB),ry(DB)
  278.         tst.b        D7
  279.         bne.S        2$
  280.         clr.l        ry(DB)            ; Released LMB
  281.         not.l        oy(DB)            ; ox/oy != mx/my
  282.         bra.S        2$
  283. 1$        btst        #xy_Change_B,D5
  284.         beq.S        CheckScreen
  285. 2$        move.w        mx(DB),D0
  286.         sub.w        rx(DB),D0
  287.         cmp.w        ox(DB),D0
  288.         beq.S        3$
  289.         lea        xyTxt+2(PC),A0
  290.         Call        MakeSNumber
  291. 3$        move.w        my(DB),D0
  292.         sub.w        ry(DB),D0
  293.         cmp.w        oy(DB),D0
  294.         beq.S        4$
  295.         lea        xyTxt+9(PC),A0
  296.         Call        MakeSNumber
  297. 4$        move.l        my(DB),oy(DB)
  298.         move.l        ThisScreen(DB),A1
  299.         lea        sc_RastPort(A1),A1
  300.         move.w        mx(DB),D0
  301.         bmi.S        5$
  302.         move.w        my(DB),D1
  303.         bmi.S        5$
  304.         Prepare        Gfx_Call
  305.         CallLib        ReadPixel
  306.         tst.l        D0
  307.         bge.S        6$
  308. 5$        lea        xyTxt+20(PC),A0
  309.         move.b        #' ',(A0)+
  310.         move.b        #' ',(A0)+
  311.         move.b        #'?',(A0)+
  312.         bra        Change
  313. 6$        cmp.w        OldColor(DB),D0
  314.         beq.s        7$
  315.         move.w        D0,OldColor(DB)
  316.         lea        xyTxt+20(PC),A0
  317.         Call        MakeUNumber
  318. 7$        bra        Change
  319.  
  320. CheckScreen    btst        #Remove_Screen_B,D5
  321.         beq.S        1$
  322.         move.l        ThisScreen(DB),A0
  323.         move.l        A0,DeadScreen(DB)
  324.         Call        FindOtherScreen        ; Find new suitable screen
  325.         beq.S        2$
  326.         move.l        D0,A1
  327.         Call        OpenNewWindow
  328.         beq.S        2$
  329.         Call        CloseOldWindow        ; We got a new window
  330.         move.l        D0,A0            ; Close the old window
  331.         Call        UseNewWindow        ; Start using the new window
  332. 1$        bra        EventLoop
  333. *»»» Couldn't jump to another screen. Now try to exit
  334. 2$        Call        RemPatches
  335.         bne.S        3$
  336.         Call        CloseOldWindow
  337.         bra        Exit
  338. 3$        Call        TellUser
  339.         bra        EventLoop
  340.  
  341.  
  342. *»»» Call:    A1 = Screen to open on
  343. *»»» Open a window
  344. OpenNewWindow    Push        D1/A0-A2/A6
  345.         Prepare        Intuition_Call
  346.         lea        NW(PC),A0
  347.         move.l        A1,nw_Screen(A0)
  348.         move.w        Width(DB),nw_Width(A0)
  349.         move.w        Height(DB),nw_Height(A0)
  350.         CallLib        OpenWindow
  351.         tst.l        D0
  352.         Pop        D1/A0-A2/A6
  353.         rts
  354.  
  355. *»»» Call:    A0 = Window to use
  356. *»»» Use new window from now on
  357. UseNewWindow    Push        D1/A0-A2/A6
  358.         Prepare        Intuition_Call
  359.         move.l        A0,ThisWindow(DB)
  360.         move.l        wd_WScreen(A0),ThisScreen(DB)
  361.         move.l        wd_RPort(A0),Rp(DB)
  362.         move.l        wd_UserPort(A0),Up(DB)
  363.         suba.l        A1,A1
  364.         lea        ScrTitle(PC),A2
  365.         CallLib        SetWindowTitles
  366.         move.l        ThisScreen(DB),A0
  367.         CallLib        ScreenToFront
  368.         Prepare        Gfx_Call
  369.         move.l        Rp(DB),A2
  370.         moveq        #0,D0            ; Assume 1.3 colors
  371.         moveq        #1,D2
  372.         tst.w        Version(DB)
  373.         beq.S        1$
  374.         exg        D0,D2            ; Well, use 2.0 colors
  375. 1$        move.l        A2,A1
  376.         CallLib        SetAPen
  377.         move.l        A2,A1
  378.         move.w        D2,D0
  379.         CallLib        SetBPen
  380.         move.l        A2,A1
  381.         moveq        #RP_JAM2,D0
  382.         CallLib        SetDrMd
  383.         move.l        Font(DB),A0
  384.         move.l        A2,A1
  385.         CallLib        SetFont
  386.         lea        Counter(PC),A0
  387.         clr.w        (A0)
  388.         lea        WLayer(PC),A0
  389.         move.l        rp_Layer(A2),(A0)
  390.         lea        WScreen(PC),A0
  391.         move.l        ThisScreen(DB),(A0)
  392.         Pop        D1/A0-A2/A6
  393.         rts
  394.  
  395. *»»» Close the window and perhaps a screen
  396. CloseOldWindow    Push        D0-D1/A0-A1/A6
  397.         Prepare        Intuition_Call
  398.         lea        WLayer(PC),A0
  399.         clr.l        (A0)            ; Disable patches
  400.         lea        WScreen(PC),A0
  401.         clr.l        (A0)            ; Disable patch
  402.         move.l        ThisWindow(DB),A0
  403.         CallLib        CloseWindow
  404.         move.l        DeadScreen(DB),D0
  405.         beq.S        1$
  406.         move.l        D0,A0
  407.         CallLib        CloseScreen        ; Close pending screen
  408. 1$        clr.l        ThisWindow(DB)
  409.         clr.l        ThisScreen(DB)
  410.         clr.l        DeadScreen(DB)
  411.         not.l        my(DB)
  412.         Pop        D0-D1/A0-A1/A6
  413.         rts
  414.  
  415. *»»» Call:    A0 = current screen or NULL
  416. *»»» Return:    D0 = new screen or NULL
  417. *»»» Tries to find a new screen big enough to open the window on
  418. FindOtherScreen Push        D1-D5/A1-A2/A6
  419.         Prepare        Exec_Call
  420.         CallLib        Forbid
  421.         Prepare        Intuition_Call
  422.         move.l        A0,D0
  423.         bne.S        1$
  424.         move.l        ib_FirstScreen(A6),D0
  425.         bra.S        CheckThisScreen
  426. 1$        move.l        sc_NextScreen(A0),D0
  427. NextScreen    tst.l        D0
  428.         bne.S        CheckThisScreen
  429.         move.l        ib_FirstScreen(A6),D0
  430. CheckThisScreen    cmp.l        A0,D0
  431.         beq.S        5$            ; Have we checked all screens ?
  432.         move.l        D0,A1
  433.         move.w        sc_ViewPort+vp_Modes(A1),D1
  434.         andi.w        #V_HIRES,D1
  435.         Prepare        Exec_Call
  436.         lea        Settings1.3H(PC),A2
  437.         cmp.w        #34,LIB_VERSION(A6)
  438.         bgt.S        1$
  439.         tst.w        D1
  440.         bne.S        2$
  441.         lea        Settings1.3L(PC),A2
  442.         bra.S        2$
  443. 1$        lea        Settings2.0H(PC),A2
  444.         tst.w        D1
  445.         bne.S        2$
  446.         lea        Settings2.0L(PC),A2
  447. 2$        movem.l        (A2),D1-D2
  448.         movem.l        D1-D2,Version(DB)    ; Initialize variables (8 bytes !!!)
  449.         moveq        #0,D1
  450.         move.b        sc_BarHeight(A1),D1
  451.         tst.w        Version(DB)
  452.         beq.S        3$
  453.         addq.w        #1,D1
  454. 3$        move.w        D1,Height(DB)
  455.         subq.w        #7,D1
  456.         lsr.w        #1,D1
  457.         addq.w        #6,D1
  458.         move.w        D1,yPos(DB)
  459.         move.w        sc_Width(A1),D1
  460.         cmp.w        Width(DB),D1
  461.         blt.S        4$
  462.         move.w        sc_Height(A1),D1
  463.         cmp.w        Height(DB),D1
  464.         bge.S        6$
  465. 4$        move.l        D0,A1
  466.         move.l        sc_NextScreen(A1),D0    ; Screen was too small, try another
  467.         bra.S        NextScreen
  468. 5$        moveq        #0,D0
  469. 6$        move.l        D0,D2
  470.         Prepare        Exec_Call
  471.         CallLib        Permit
  472.         move.l        D2,D0
  473.         Pop        D1-D5/A1-A2/A6
  474.         rts
  475.  
  476. *»»» Write the string
  477. UpdateDisplay    Prepare        Gfx_Call
  478.         move.l        Rp(DB),A1
  479.         move.w        xPos(DB),D0
  480.         move.w        yPos(DB),D1
  481.         CallLib        Move
  482.         lea        xyTxt(PC),A0
  483.         move.l        Rp(DB),A1
  484.         moveq        #StringLength,D0
  485.         CallLib        Text
  486.         rts
  487.  
  488. *»»» These routines return the colors that Kickstart 2.x uses for
  489. *»»» title-text and window-frames in active windows. Perhaps I
  490. *»»» am using system-private values here - I didn't have access
  491. *»»» Kickstart 2.x includes and autodocs when I wrote this.
  492. *»»»
  493. *»»» Return:    D0 = Color used for title-text in active windows.
  494. GetFrontColor    moveq        #12,D0
  495.         bra.S        GetColor
  496. *»»» Return:    D0 = Color used for window-frames in active windows.
  497. GetBackColor    moveq        #10,D0
  498. GetColor    move.l        ThisWindow(DB),A0
  499.         move.l        wd_WScreen(A0),A0
  500.         move.l        $1DE+4(A0),A0
  501.         move.w        0(A0,D0.W),D0
  502.         rts
  503.  
  504. *»»» Make an unsigned number
  505. MakeUNumber    moveq        #' ',D1
  506.         bra.S        NEG
  507. *»»» Make a signed number
  508. MakeSNumber    moveq        #' ',D1
  509.         ext.l        D0
  510.         bge.S        POS
  511.         neg.l        D0
  512.         move.b        #'-',(A0)+
  513.         bra.S        NEG
  514. POS        move.b        D1,(A0)+
  515. NEG        move.b        D1,(A0)+
  516.         move.b        D1,(A0)+
  517.         moveq        #'0',D1
  518.         move.b        D1,(A0)+
  519. 1$        tst.l        D0
  520.         beq.S        2$
  521.         divu        #10,D0
  522.         swap        D0
  523.         add.w        D1,D0
  524.         move.b        D0,-(A0)
  525.         clr.w        D0
  526.         swap        D0
  527.         bra.S        1$
  528. 2$        rts
  529.  
  530. *»»» Call:    A0 = Text to display
  531. TellUser    Push        D0-D3/A0-A3/A6
  532.         lea        ITxtAUTOBody(PC),A1
  533.         move.l        ThisWindow(DB),A0
  534.         suba.l        A2,A2    
  535.         lea        ITxtAUTOPos(PC),A3
  536.         moveq        #0,D0
  537.         moveq        #0,D1
  538.         move.w        #220,D2
  539.         moveq        #47,D3
  540.         Prepare        Intuition_Call
  541.         CallLib        AutoRequest
  542.         Pop        D0-D3/A0-A3/A6
  543.         rts
  544.  
  545. *»»» Patch the 'LockLayerRom',
  546. *»»»       the 'UnlockLayerRom' and
  547. *»»»       the 'CloseScreen' functions
  548. AddPatches    Push        D0-D1/A0-A1/A6
  549.         Prepare        Exec_Call
  550.         CallLib        Forbid
  551.         lea        LockPatch(PC),A0    ; Patch 'LockLayerRom'
  552.         move.l        A0,D0
  553.         move.l        GraphBase(DB),A1
  554.         move.w        #_LVOLockLayerRom,A0
  555.         CallLib        SetFunction
  556.         move.l        D0,JmpOldLock+2
  557.         lea        UnlockPatch(PC),A0    ; Patch 'UnlockLayerRom'
  558.         move.l        A0,D0
  559.         move.l        GraphBase(DB),A1
  560.         move.w        #_LVOUnlockLayerRom,A0
  561.         CallLib        SetFunction
  562.         move.l        D0,JmpOldUnlock+2
  563.         lea        CloseSPatch(PC),A0    ; Patch 'CloseScreen'
  564.         move.l        A0,D0
  565.         move.l        IntuiBase(DB),A1
  566.         move.w        #_LVOCloseScreen,A0
  567.         CallLib        SetFunction
  568.         move.l        D0,JmpOldCloseS+2
  569.         CallLib        Permit
  570.         Pop        D0-D1/A0-A1/A6
  571.         rts
  572.  
  573. *»»» Restore the old 'LockLayerRom',
  574. *»»»         the old 'UnlockLayerRom' and
  575. *»»»         the old 'CloseScreen' functions
  576. *»»» If any of these functions has patched since we did it, then fail !
  577. RemPatches    Push        D1-D2/A0-A1/A6
  578.         Prepare        Exec_Call
  579.         CallLib        Forbid
  580.         moveq        #1,D2
  581.         move.l        IntuiBase(DB),A0
  582.         lea        CloseSPatch(PC),A1
  583.         cmp.l        _LVOCloseScreen+2(A0),A1    ; Anyone else patching 'CloseScreen' ?
  584.         bne.S        1$
  585.         move.l        GraphBase(DB),A0
  586.         lea        UnlockPatch(PC),A1
  587.         cmp.l        _LVOUnlockLayerRom+2(A0),A1    ; Anyone else patching 'UnLockLayerRom' ?
  588.         bne.S        1$
  589.         lea        LockPatch(PC),A1
  590.         cmp.l        _LVOLockLayerRom+2(A0),A1    ; Anyone else patching 'LockLayerRom' ?
  591.         bne.S        1$
  592.         move.l        JmpOldCloseS+2(PC),D0    ; Restore 'CloseScreen' !
  593.         move.l        IntuiBase(DB),A1
  594.         move.w        #_LVOCloseScreen,A0
  595.         CallLib        SetFunction
  596.         move.l        JmpOldUnlock+2(PC),D0    ; Restore 'UnlockLayerRom' !
  597.         move.l        GraphBase(DB),A1
  598.         move.w        #_LVOUnlockLayerRom,A0
  599.         CallLib        SetFunction
  600.         move.l        JmpOldLock+2(PC),D0    ; Restore 'LockLayerRom' !
  601.         move.l        GraphBase(DB),A1
  602.         move.w        #_LVOLockLayerRom,A0
  603.         CallLib        SetFunction
  604.         moveq        #0,D2
  605. 1$        CallLib        Permit
  606.         move.l        D2,D0
  607.         Pop        D1-D2/A0-A1/A6
  608.         rts
  609.  
  610. *»»» Call:    A1 = DB
  611. *»»» Inside the server the registers D0-D1/A0-A1/A5-A6 can be used
  612. *»»» without restoring them on exit
  613. xyIntServer    btst        #6,LMBBUT
  614.         seq        D1
  615.         cmp.b        Relative(A1),D1
  616.         beq.S        1$
  617.         move.b        D1,Relative(A1)
  618.         move.l        ThisScreen(A1),A0
  619.         move.l        sc_MouseY(A0),my(A1)
  620.         move.l        #LMB_Change_F,D0
  621.         bra.S        2$
  622. 1$        move.l        ThisScreen(A1),A0
  623.         move.l        sc_MouseY(A0),D1
  624.         cmp.l        my(A1),D1
  625.         beq.S        3$
  626.         move.l        D1,my(A1)
  627.         move.l        #xy_Change_F,D0
  628. 2$        move.l        xyProcess(A1),A1
  629.         Prepare        Exec_Call
  630.         CallLib        Signal
  631. 3$        moveq        #0,D0            ; Set the Z flag
  632.         rts
  633.  
  634. *»»» These patch-functions prevents the graphics functions to
  635. *»»» 'LockLayerRom' and 'UnlockLayerRom' on my windows layer
  636. *»»»
  637. *»»» Any calls to 'LockLayerRom' that had not yet been matched
  638. *»»» by a 'UnlockLayerRom' when these pathches got installed, can
  639. *»»» still use 'UnlockLayerRom' normally because of the counter.
  640. LockPatch    cmp.l        WLayer(PC),A5
  641.         bne.S        JmpOldLock
  642.         addq.w        #1,Counter
  643.         rts
  644. JmpOldLock    jmp        12345678        ; Not my windows layer
  645.  
  646. UnlockPatch    cmp.l        WLayer(PC),A5
  647.         bne.S        JmpOldUnlock
  648.         subq.w        #1,Counter
  649.         bmi.S        JmpOldUnlock
  650.         rts
  651. JmpOldUnlock    jmp        12345678        ; Not my windows layer
  652. WLayer        dc.l        0            ; Layer to compare against
  653. Counter        dc.w        0            ; Coordination counter
  654.  
  655. *»»» This patch-function helps Mouse-xy evacuate any closing screen.
  656. *»»» I don't just close the window here because I don't know what the
  657. *»»» Mouse-xy process is doing to the window at this moment. I don't
  658. *»»» even close the screen here but instead I signal process to close
  659. *»»» the window and screen under more controlled circumstances.
  660. CloseSPatch    cmp.l        WScreen(PC),A0
  661.         bne.S        JmpOldCloseS
  662.         Push        D0-D1/A0-A1/A6
  663.         move.l        #Remove_Screen_F,D0
  664.         move.l        WProcess(PC),A1
  665.         Prepare        Exec_Call
  666.         CallLib        Signal
  667.         Pop        D0-D1/A0-A1/A6
  668.         rts
  669. JmpOldCloseS    jmp        12345678        ; Not my windows screen
  670. WScreen        dc.l        0            ; Screen to compare against
  671. WProcess    dc.l        0            ; Process to signal
  672.  
  673. StringLength    =23
  674. StringSpace    =StringLength*8
  675.  
  676. Kick1        =0
  677. *»»» Defines for hires under kickstart 1.2-1.3 (and below ?)
  678. Width1.3H    =84+StringSpace
  679. Height1.3H    =10
  680. xPos1.3H    =30
  681.  
  682. *»»» Defines for lores under  kickstart 1.2-1.3 (and below ?)
  683. Width1.3L    =51+StringSpace
  684. Height1.3L    =10
  685. xPos1.3L    =16
  686.  
  687. Kick2        =1
  688. *»»» Defines for hires under kickstart 2.0 (and up ?)
  689. Width2.0H    =51+StringSpace
  690. Height2.0H    =11
  691. xPos2.0H    =23
  692.  
  693. *»»» Defines for lores under kickstart 2.0 (and up ?)
  694. Width2.0L    =40+StringSpace
  695. Height2.0L    =11
  696. xPos2.0L    =18
  697.  
  698. Settings1.3H    dc.w        Kick1,Width1.3H,Height1.3H,xPos1.3H
  699. Settings1.3L    dc.w        Kick1,Width1.3L,Height1.3L,xPos1.3L
  700. Settings2.0H    dc.w        Kick2,Width2.0H,Height2.0H,xPos2.0H
  701. Settings2.0L    dc.w        Kick2,Width2.0L,Height2.0L,xPos2.0L
  702.  
  703. GfxName        dc.b        'graphics.library',0
  704. IntuiName    dc.b        'intuition.library',0
  705. xyIntName    dc.b        'xy Interrupt',0
  706. xyTxt        dc.b        'x:   0 y:   0 Color:  0',0
  707. ScrTitle    dc.b        'Mouse-xy V1.1 1991 by Preben Nielsen',0
  708.         EVEN
  709.  
  710. IDCMP_Flags    =        CLOSEWINDOW|MOUSEBUTTONS|INACTIVEWINDOW|ACTIVEWINDOW
  711. Other_Flags    =        RMBTRAP|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG
  712. NW        dc.w        0,0,0,0
  713.         dc.b        0,1
  714.         dc.l        IDCMP_Flags,Other_Flags,0,0,0,0,0
  715.         dc.w        0,0,0,0,CUSTOMSCREEN
  716.  
  717. ITxtAUTOBody    IntuiText    AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,8,4,TxtCantLeave1,0    ;ITxtAUTOBody2
  718. ITxtAUTOPos    IntuiText    AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,6,3,TxtPos,0
  719. TxtPos        dc.b        'Stay',0
  720. TxtCantLeave1    dc.b        "Mouse-xy: Can't exit !!",0
  721.         EVEN
  722. TxtAttr        dc.l        FontName
  723.         dc.w        TOPAZ_EIGHTY
  724.         dc.b        FS_NORMAL,FPB_ROMFONT
  725. FontName    dc.b        'topaz.font',0
  726.         END
  727.  
  728.